const fn1 = () => console.log('被执行')
const fn2 = () => console.log('被拦截')

const once = (fn, errFn = function(){}) => {
  let firstRun = true
  // 返回一个函数实现闭包
  return function() {
    firstRun ? (fn(), firstRun = !firstRun) : errFn()
  }
}

const test = once(fn1, fn2)
for(let i = 0 ; i< 5; i++) {
  test()
}
